// https://www.lintcode.com/problem/295/?_from=collection&fromId=186

class Solution {
public:
    /**
     * @param a: first sequence
     * @param b: second sequence
     * @return: return ans
     */
    // 注意是两个序列相交的区间的下标
    vector<vector<int>> Intersection(vector<vector<int>> &a, vector<vector<int>> &b) {
        vector<vector<int>> res;
        int pa = 0;
        int pb = 0;
        while (pa < a.size() && pb < b.size()) {
            if (a[pa][0] <= b[pb][0]){
                if (a[pa][1] >= b[pb][0]) {
                    res.push_back(vector<int>{pa, pb});
                    
                }
            } else if (a[pa][0] <= b[pb][1]) {
                res.push_back(vector<int>{pa, pb});
            }
            if (a[pa][1] > b[pb][1]) pb++;
            else pa++;
        }
        return res;
    }
};